package com.AIDS.AIDSweeper.server.model.DAO;

public class GoogleDAOFactory extends DAOFactory {

	public GameDAO gameInstance;
	public MineDAO mineInstance;
	public GamerDAO gamerInstance;
	public PlayerDAO playerInstance;
	
	
	@Override
	public GameDAO getGameDAO() {
		if(gameInstance == null)
			gameInstance = (GameDAO)instantiateDAO(GameDAO.class);
		return gameInstance;
	}

	@Override
	public GamerDAO getGamerDAO() {
		if(gamerInstance == null)
			
			gamerInstance = (GamerDAO)instantiateDAO(GamerDAO.class);
		return gamerInstance;
	}

	@Override
	public MineDAO getMineDAO() {	
		if(mineInstance == null)
			
			mineInstance = (MineDAO)instantiateDAO(MineDAO.class);
		return mineInstance;
	}

	@Override
	public PlayerDAO getPlayerDAO() {
		if(playerInstance == null)
			
			playerInstance = (PlayerDAO)instantiateDAO(PlayerDAO.class);
		return playerInstance;
	}

	 @SuppressWarnings("unchecked")
	private GoogleJDODAO instantiateDAO(Class daoClass) {
	        try {
	        	GoogleJDODAO dao = (GoogleJDODAO)daoClass.newInstance();
	            return dao;
	        } catch (Exception ex) {
	            throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
	        }
	    }
}
